﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using TowerDefenseKaZ.src;
using MySql.Data.MySqlClient;

namespace TowerDefenseKaZ.src
{
    public abstract class Sprite
    {
        protected GameWindow Window;
        protected Texture2D image;
        protected Vector2 gravityForce;
        protected Vector2 position;
        public bool isFall;
        public Vector2 Position
        {
            get
            {
                return position;
            }
            set
            {
                position = value;
            }
        }
        protected Vector2 speed;
        protected bool isMoving;
        protected Rectangle origem;
        protected Rectangle destino;
        protected float rotation;
        protected Vector2 pivo;
        protected bool rightDirection;
        public bool visible;
        protected float index;
        public int mass;
        protected float alfa;
        protected Color color;
        protected Rectangle colision;
        public Rectangle Colision
        {
            get
            {
                return colision;
            }
            set
            {
                colision = value;
            }
        }
        public struct Animation
        {
            public int frame_X; // widht of Frame.
            public int frame_Y; //Height of Frame .
            public int framesTotal; // Frames totals of animation.
            public int now_frame; // Frame atual;
            public int fps; // Frames for seconds
            public int Y;// Line of animation frame; 
            public string name; // name in string of animation.
         

        }
        
        protected Animation animation;
        protected Animation currentAnim, lastAnim;

        public Sprite(Texture2D image, GameWindow Window)
        {
            this.image = image;
            this.Window = Window;
            this.visible = true;
            this.alfa = 1;
            this.gravityForce = new Vector2(2, 2);
            this.isFall = true;

        }//SpriteConstruct
        public abstract void Update(GameTime gameTime);//Update Abstract
        public bool checkColision(Sprite other)
        {
            if (this.Colision.Intersects(other.Colision))
            {
                return true;
            }
            else
            {
                return false;
            }
        }//checkColision
        public void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            if (this.visible)
            {
                int frame = (int)(gameTime.TotalGameTime.TotalSeconds * animation.fps) % animation.framesTotal;

                spriteBatch.Draw(
                    image,
                    new Rectangle(
                        (int)position.X,
                        (int)position.Y,
                        animation.frame_X,
                        animation.frame_Y),
                    new Rectangle(
                        frame * animation.frame_X,
                        animation.Y,
                        animation.frame_X,
                        animation.frame_Y),
                    new Color(
                        1.0f * alfa,
                        1.0f * alfa,
                        1.0f * alfa,
                        alfa),
                        rotation,
                        pivo,
                        (rightDirection) ? SpriteEffects.None : SpriteEffects.FlipHorizontally,
                        index);
                
            }

        }//Draw


    }//Sprite
}//nameSpace
